package ga;

import java.util.Map;
import java.util.HashMap;

//MODIFICAR, HASHMAP QUE CONTIENE LEX - TIPO Y LEX - DIR
public class TS {
	
   private Map<String,ObjTipo> tablaLexTipo; 
   private Map<String,Integer> tablaLexDir; 
   
   public TS() {
     tablaLexTipo = new HashMap<String,ObjTipo>();
     tablaLexDir = new HashMap<String,Integer>();
   }
   
   private TS(Map<String,ObjTipo> tablaLexTipo, Map<String,Integer> tablaLexDir) {
     this.tablaLexTipo = tablaLexTipo;
     this.tablaLexDir = tablaLexDir; 
   }
   
   public boolean estaEn(String lex) {
      return tablaLexTipo.containsKey(lex) && tablaLexDir.containsKey(lex); 
   }
   
   public TS aniade(String lex,ObjTipo tipo, Integer dir) {
       TS result = new TS(new HashMap<String,ObjTipo>(tablaLexTipo), new HashMap<String,Integer>(tablaLexDir));
       result.tablaLexTipo.put(lex,tipo);
       result.tablaLexDir.put(lex,dir);
       return result;
   }
   
   public TS borraLex(String lex){
	   TS result = new TS(new HashMap<String,ObjTipo>(tablaLexTipo), new HashMap<String,Integer>(tablaLexDir));
       result.tablaLexTipo.remove(lex);
       result.tablaLexDir.remove(lex);
       return result;
   }
   
   public ObjTipo tipoDe(String lex) {
       return tablaLexTipo.get(lex);
   }
   
   public int dirDe(String lex) {
       return tablaLexDir.get(lex);
   }
   
   public String toString() {
       return tablaLexTipo.toString() + tablaLexDir.toString();
   }
}
